<template>
	<view>
		<!-- 查看详情 -->
		<view v-if="type == 1">
			<uni-card title="企业基本信息">
			  <!-- 企业基本信息 -->
			  <view>企业名称：<span>{{ information.name }}</span></view>
			  <view>认证状态：<uni-tag text="已认证" type="success" v-if="information.isCertify == 1" />
			  <uni-tag text="未认证" type="warning" v-else />
			  </view>
			  <view>统一社会信用代码：<span>{{ information.creditCode }}</span></view>
			  <view>法人：<span>{{ information.leader }}</span></view>
			  <view>企业所在地址：<span v-if="information.invoiceAddress != null">{{ information.invoiceAddress }}</span><span v-else>--</span></view>
			  <view>企业联系电话：<span v-if="information.invoiceTelephone != null">{{ information.invoiceTelephone }}</span><span v-else>--</span></view>
			  <view>客户类别：<span v-if="information.customerType == $order.ec_customer_type.sale">销售客户</span>
			  <span v-if="information.customerType == $order.ec_customer_type.supply">供应客户</span></view>
			  <view>备注：<span v-if="information.remark != null">{{ information.remark }}</span><span v-else>--</span></view> 
			  <view>变更时间：<span v-if="information.updateTime != null">{{ information.updateTime }}</span><span v-else>--</span></view>
			  <view>创建时间：<span>{{ information.createTime }}</span></view>
			  <view>黑名单：<uni-tag text="是" type="warning" v-if="information.status == 1" />
			  <uni-tag text="否" type="success" v-else /></view>
			  <!-- 企业发票信息  v-model="activeNames" -->
			  <uni-collapse ref="collapse">
			  		<uni-collapse-item title="企业发票信息" >
			  			<view class="content">
			  			<view>发票类型：<span v-if="information.invoiceType != null">{{ (information.invoiceType == 0) ? '增值税普通发票' : '增值税专用发票' }}</span>
			  			 <span v-else>--</span></view>
			  			<view>发票抬头：<span v-if="information.name != null">{{ information.name }}</span>
			  			 <span v-else>--</span></view>
			  			<view>企业税号：<span  v-if="information.creditCode != null">{{ information.creditCode }}</span>
			  			<span v-else>--</span></view> 
			  			<view>开户银行名称：<span v-if="information.bankName != null">{{information.bankName}}</span>
			  			<span v-else>--</span></view>
			  			<view>开户银行账号：<span v-if="information.account != null">{{information.account}}</span>
			  			<span v-else>--</span></view>
			  			<view>企业邮箱账号：<span v-if="information.email != null">{{information.email}}</span>
			  			<span v-else>--</span></view>
			  			<view>企业联系电话：<span v-if="information.invoiceTelephone != null">{{information.invoiceTelephone}}</span>
			  			<span v-else>--</span></view>
			  			<view>企业所在地址：<span v-if="information.invoiceAddress != null">{{information.invoiceAddress}}</span>
			  			<span v-else>--</span></view>
			  			</view>
			  		</uni-collapse-item>
						
			  <!-- 企业对公账户信息 -->
			  		<uni-collapse-item title="企业对公账户信息" >
			  		 		<view class="content">
			  				<view>开户银行名称：<span v-if="information.bankName != null">{{information.bankName}}</span>
			  				<span v-else>--</span></view>
			  				<view>开户支行账号：<span v-if="information.bankSonName != null">{{information.bankSonName}}</span>
			  				<span v-else>--</span></view>
			  				<view>企业账户名称：<span v-if="information.name != null">{{information.name}}</span>
			  				<span v-else>--</span></view>
							<view>开户银行账号：<span v-if="information.account != null">{{information.account}}</span>
							<span v-else>--</span></view>
			  		 		</view>
			  		</uni-collapse-item>
			  	</uni-collapse> 					
			</uni-card>
		</view>
		
		<!-- 修改 -->
		<view v-else>
			<uni-notice-bar single color="#00a660" background-color="#e6f6ef" :text="titleBar"/>
			<uni-forms ref="ruleForm" :modelValue="ruleForm" :rules="rules" label-width="260rpx" type="line" label-align="right" class="change_form">
				<uni-forms-item label="企业名称" name="name" :required="true">
					<uni-easyinput v-model="ruleForm.name" type="text" placeholder="请输入企业名称" :clearable="false" :maxlength="50" :disabled="ruleForm.isCertify == 1" />
				</uni-forms-item> 
				<uni-forms-item label="企业法人" name="leader" :required="true">
					<uni-easyinput v-model="ruleForm.leader" type="text" placeholder="请输入企业法人" :clearable="false" :maxlength="30" :disabled="ruleForm.isCertify == 1" />
				</uni-forms-item>
				<uni-forms-item label="统一社会信用代码" name="creditCode" :required="true">
					<uni-easyinput v-model="ruleForm.creditCode" type="text" placeholder="请输入统一社会信用代码" :clearable="false" :maxlength="18" :disabled="ruleForm.isCertify == 1" />
				</uni-forms-item>
				<uni-forms-item label="客户类别" name="customerType" :required="false">
					<uni-data-select v-model="ruleForm.customerType" :localdata="customerTypeArr" :clear="false" placeholder="请选择客户类别"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="发票类型" name="invoiceType" :required="false">
					<uni-data-select v-model="ruleForm.invoiceType" :localdata="invoiceList" :clear="false" @change="selectContractType" placeholder="请选择发票类型"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="开户银行名称" name="bankName" :required="false">
					<uni-easyinput v-model="ruleForm.bankName" type="text" placeholder="请输入开户银行名称" :clearable="false" />
				</uni-forms-item>
				<uni-forms-item label="开户支行账号" name="bankSonName" :required="false">
					<uni-easyinput v-model="ruleForm.bankSonName" type="text" placeholder="请输入开户支行账号" :clearable="false" />
				</uni-forms-item>
				<uni-forms-item label="企业对公账户" name="account" :required="false">
					<uni-easyinput v-model="ruleForm.account" type="text" placeholder="请输入企业对公账户" :clearable="false" />
				</uni-forms-item>
				<uni-forms-item label="企业联系电话" name="invoiceTelephone" :required="false">
					<uni-easyinput v-model="ruleForm.invoiceTelephone" type="text" placeholder="请输入企业邮箱账号" :clearable="false" />
				</uni-forms-item>
				<uni-forms-item label="企业邮箱账号" name="email" :required="false">
					<uni-easyinput v-model="ruleForm.email" type="text" placeholder="请输入企业邮箱账号" :clearable="false" />
				</uni-forms-item>
				<uni-forms-item label="企业所在地址" name="email" :required="false">
					<uni-easyinput v-model="ruleForm.email" type="text" placeholder="请输入邮箱" :clearable="false"/>
				</uni-forms-item>
				<uni-forms-item label="备注" name="remark" :required="false">
					<uni-easyinput v-model="ruleForm.remark" type="textarea" placeholder="点击添加备注,最多200字!" :clearable="false" />
				</uni-forms-item>
				<view class="submit_btn flex_between">
					<button size="mini" class="back-Btn" @click="cancel">取消</button>
					<button size="mini" class="next-Btn" @click="submit">确定</button>
				</view>
			</uni-forms>
			</view>
	</view>
</template>

<script>
	import {addCustomerCompany,getCustomerCompany,updateCustomerCompany} from "@/api/ec/work/customer/customerCompany";
	export default {
		data() {
			return {
				titleBar:'修改企业信息资料',
				customerTypeArr:[{text:'销售客户',value:0},{text:'供应客户',value:1}], //客户类别 
				// activeNames:['0'], // 默认展开
				information:'',
				type:'', //0修改 1查看 
				invoiceList:[],
				// 表单参数
				ruleForm: {},
				// 表单校验 
				rules: {
				  name: [
				    {required: true, message: "请输入企业名称", trigger: "blur"},
				    {min: 2, max: 30, message: '企业名称长度需要在2-30个汉字或字符之间，不能包含特殊字符', trigger: 'blur'},
				  ],
				  leader: [
				    {required: true, message: "请输入企业法人", trigger: "blur"},
				    {min: 2, max: 30, message: '企业法人长度需要在2-30个汉字或字符之间，不能包含特殊字符', trigger: 'blur'},
				    ],
				  creditCode: [
				    {required: true, message: "请输入统一社会信用代码", trigger: "blur"},
				    {
				        pattern: /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/,
				        message: "请输入正确的统一社会信用代码",
				        trigger: "blur"
				    }
				    ],        
				},
			}
		},
		onLoad(option) {
			if(option.item){
			this.information = JSON.parse(option.item)
			this.ruleForm = this.information
			this.type = option.type
			}
		},
		methods: {
			cancel(){
				uni.navigateBack({ 
					delta:1
				})
			},
			/** 修改 */ 
			submit(){
				this.$refs.ruleForm.validate().then(res => {
				if (this.ruleForm.id != null) {
				      updateCustomerCompanyStaff(this.ruleForm).then(response => {
				        this.$modal.msgSuccess("修改成功");
						uni.$emit('refreshData');
						uni.navigateBack({
							delta:1
						})
				      }); 
				    } else { 
				      addCustomerCompanyStaff(this.ruleForm).then(response => {
				        this.$modal.msgSuccess("新增成功");
						uni.$emit('refreshData');
						uni.navigateBack({
							delta:1
						})
				      });
				    }
				});          
			},
		}
	}
</script>

<style scoped lang="scss">
::v-deep .uni-input-input:disabled{color:#666666;}	
.submit_btn{
	margin-top: 52rpx;
	padding-bottom: 52rpx;
	justify-content: space-around;
	button{
		width: 42%;
		font-size: 28rpx;
	}
	.next-Btn{
		background-color: $uni-color-primary;
		border-radius: 10rpx;
		color: #fff;
	}
		
	.back-Btn{
		border-radius: 10rpx;
		border: solid 1rpx $uni-color-primary;
		color: $uni-color-primary;
		background: #fff;
	}
	
}	
::v-deep .uni-forms-item{margin-bottom: 26rpx;}
.change_form {padding:0 30rpx 0 20rpx;position: relative;}
::v-deep .uni-collapse-item__title-box{background: #fff;padding: 0;}
::v-deep .uniui-bottom{color: #ccc !important;}
page{background: $uni-bg-color;}
view{margin-bottom: 16rpx;}
span{font-weight: 600;}
</style>
